<template>
	<!-- 领料单维护 -->
	<div>
		<v-container row class="text-subtitle-1 d-flex justify-center  align-left">

			<!-- <v-btn class="ml-2 mt-5" small tile color="success"
				@click="requestOrtransferOrder=1,createProductionPickingForMasterVisable=true">
				为母工单创建领料单
			</v-btn> -->

			<v-divider class="mx-4" inset vertical></v-divider>
			<v-radio-group class="MaxWidthSelect" v-model="tabTwoRequestOrderInputType" row mandatory>
				<v-radio label="物料代码" value="1"></v-radio>
				<v-radio label="物料名称" value="2"></v-radio>
				<v-radio label="工单号" value="3"></v-radio>
			</v-radio-group>

			<v-text-field fiexd v-model="tabTwoRequestOrderSearchInput" append-icon="mdi-magnify"
				label="输入物料代码或物料名称或工单号，按回车" single-line hide-details autocomplete
				@keypress.enter="loadAllMaterialRequestOrderList"></v-text-field>
		</v-container>
		<br />

		<v-data-table :headers="tabTwoRequestMaterialOrderHeader" :items="requestMaterialOrderList" small fixed-header
			item-key="id" dense class="text-no-wrap" loading-text="正在加载请稍等......" :options.sync="tabTwoOptions"
			:footer-props="vuetifyDefaultPage" :loading="tabTwoLoading" :server-items-length="tabTwoTotalCount">
			<template v-slot:item.actions="{ item }">
				<div>
					<v-btn class="ml-2" small tile color="success"
						@click="editTabTwoRequestMaterialDialog=true,editTabTwoRequestMaterial=item">
						修改
					</v-btn>
					<v-btn class="ml-2" small tile color="deep-orange"
						@click="deleteTabTwoRequestMaterialOrder(item.id)">
						删除
					</v-btn>
				</div>
			</template>
		</v-data-table>

		<!--页签二：为母工单创建领料单 -->
		<v-dialog v-model="createProductionPickingForMasterVisable" max-width="1200px">
			<v-card>
				<v-card-title>
					<span class="text-h5">为母工单创建领料单</span>
				</v-card-title>
				<v-card-text>
					<div class="mb-12">
						<v-row dense>
							<v-col cols="6">
								<v-alert text color="blue-grey">选择物料信息</v-alert>
								<v-text-field v-model="rightMaterialSearch" append-icon="mdi-magnify"
									label="输入物料编码或物料名称,按回车" single-line hide-details
									@keypress.enter="loadmaterialDataList(1)">
								</v-text-field>

								<v-data-table dense :headers="MaterialRequestOrderHeader" :items="materialDataList"
									:options.sync="tabOneOptions" :footer-props="vuetifyDefaultPage"
									:server-items-length="tabOneTotalCount" item-key="id" class="text-no-wrap mt-2"
									fixed-header>
									<template v-slot:item.check="{item }">
										<v-checkbox v-model="item.check" style="height:20px;" class="mb-5"
											@click="rightMaterialCheckEvent(item)"></v-checkbox>
									</template>

									<template v-slot:item.needqty="props">
										<v-edit-dialog large @save="saveNeedQty" save-text="保存数量" cancel-text="取消">
											<a>
												{{ props.item.needqty}}
											</a>
											<v-icon small class="mr-2" color="red">
												mdi-pencil
											</v-icon>
											<template v-slot:input>
												<div class="mt-4 text-h6">
													添加领料数量
												</div>
												<v-text-field label="领料数量" :rules="leftNeedQtyRule"
													v-model="props.item.needqty"></v-text-field>
											</template>
										</v-edit-dialog>
									</template>

									<!-- 描述编辑 -->
									<template v-slot:item.description="props">
										<v-edit-dialog large save-text="保存" cancel-text="取消">
											<a>
												{{ props.item.description}}
											</a>
											<v-icon small class="mr-2" color="red">
												mdi-pencil
											</v-icon>
											<template v-slot:input>
												<div class="mt-4 text-h6">
													编辑备注
												</div>
												<v-textarea outlined name="input-7-4" label="备注"
													v-model="props.item.description" :value="props.item.description">
												</v-textarea>
											</template>
										</v-edit-dialog>
									</template>

								</v-data-table>
							</v-col>
							<v-col cols="6">
								<v-alert text color="blue-grey">选择母工单</v-alert>
								<v-row>
									<v-col cols="12">
										<v-text-field v-model="masterOrderSearchInput" append-icon="mdi-magnify"
											label="输入项目号或项目名称或母工单号或母工单名称,按回车" single-line hide-details
											@keypress.enter="loadMasterOrderList">
										</v-text-field>
										<v-data-table :headers="masterOrderHeaderList" :items="masterOrderList"
											:options.sync="masterOrderOptions" :footer-props="vuetifyDefaultPage"
											:loading="masterOrderLoading" :server-items-length="masterOrderTotalCount"
											item-key="id" class="text-no-wrap mt-2" fixed-header>
											<template v-slot:item.check="{item }">
												<v-checkbox v-model="item.check" style="height:20px;" class="mb-5">
												</v-checkbox>
											</template>
										</v-data-table>
									</v-col>
								</v-row>
							</v-col>
						</v-row>
					</div>
					<div ref="print" id="printMasterWithRequestOrder" style="align-items: center;display: none;">
						<table class="tab">
							<tbody class="top-tbody">
								<tr>
									<td style="font-weight:bold; text-align:center;" colspan="6">领料单</td>
								</tr>
								<tr style="height:25px;">
									<td style="font-weight:bold">领料单号</td>
									<td style="text-align: center;">
										{{MaterialOtherInfo.bigRequestCode}}
									</td>
									<td style="font-weight:bold">领料部门</td>
									<td style="text-align: center;">
										{{MaterialOtherInfo.departname}}
									</td>
									<td style="font-weight:bold">制单时间</td>
									<td style="text-align: center;">
										{{MaterialOtherInfo.now|dateFormat}}
									</td>
								</tr>
							</tbody>
						</table>
						<table class="tab" style="border-top:none;">
							<tbody class="bottom-tbody">
								<tr>
									<td style="font-weight:bold; text-align:center;" colspan="5">物料信息</td>
								</tr>
								<tr class="tr-head" style="height:25px;">
									<td class="td-bold td-center column-1">物料编码</td>
									<td class="td-bold td-center column-2">物料名称</td>
									<td class="td-bold td-center column-3">物料规格</td>
									<td class="td-bold td-center column-4">数量</td>
									<td class="td-bold td-center column-5">单位</td>
								</tr>
								<tr v-for="requestOrder in  checkMaterialRequestOrderList"
									:key="requestOrder.materialid" class="tr-body" style="height:25px;">
									<td class="td-body-color td-center column-1 column-body-1">
										{{requestOrder.materialcode}}
									</td>
									<td class="td-body-color td-center column-2 column-body-2">
										{{requestOrder.materialname}}
									</td>
									<td class="td-body-color td-center column-3 column-body-3">
										{{requestOrder.materialspecification}}
									</td>
									<td class="td-body-color td-center column-4 column-body-4">
										{{requestOrder.needqty}}
									</td>
									<td class="td-body-color td-center column-5 column-body-5">
										{{requestOrder.unitname}}
									</td>
								</tr>
							</tbody>
						</table>
						<v-row class="mt-2">
							<v-col cols="3">开单人: {{MaterialOtherInfo.applyusername}}</v-col>
							<v-col cols="3">领料人:</v-col>
							<v-col cols="3">仓管员:</v-col>
							<v-col cols="3">审核人:</v-col>
						</v-row>
					</div>

				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="blue darken-1" text @click="createMasterOrderRequestOrderSubmit">
						打印
					</v-btn>
					<v-btn color="blue darken-1" text @click="cancelAddMaterialRequestOrder">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>

		<!-- 页签二-编辑领料单对话框 -->
		<v-dialog v-if="editTabTwoRequestMaterial!=null" v-model="editTabTwoRequestMaterialDialog" max-width="800px">
			<v-card>
				<v-card-title>
					<span class="text-h5">编辑领料单信息</span>
				</v-card-title>
				<v-card-text>
					<v-form ref="form" v-model="editTabTwoRequestMaterialValid">
						<v-row>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="领料单编号" disabled v-model="editTabTwoRequestMaterial.code">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="项目号" disabled v-model="editTabTwoRequestMaterial.projectcode">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field v-if="editTabTwoRequestMaterial.childrenOrder!=null" label="子工单号" disabled
									v-model="editTabTwoRequestMaterial.childrenOrder.code">
								</v-text-field>
								<v-text-field v-else label="子工单号" disabled>
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field v-if="editTabTwoRequestMaterial.masterOrder!=null" label="母工单号" disabled
									v-model="editTabTwoRequestMaterial.masterOrder.workcode">
								</v-text-field>
								<v-text-field v-else label="母工单号" disabled>
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="物料代码" disabled v-model="editTabTwoRequestMaterial.materialcode">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="物料名称" disabled v-model="editTabTwoRequestMaterial.materialname">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="仓库" disabled v-model="editTabTwoRequestMaterial.storagename">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="需求数量" v-model="editTabTwoRequestMaterial.needqty"
									:rules="leftNeedQtyRule">
								</v-text-field>
							</v-col>
							<v-col cols="12">
								<v-textarea outlined name="input-7-4" label="备注"
									v-model="editTabTwoRequestMaterial.description"
									:value="editTabTwoRequestMaterial.description">
								</v-textarea>
							</v-col>
						</v-row>
					</v-form>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="blue darken-1" text :disabled="!editTabTwoRequestMaterialValid"
						@click="editTabTwoRequestMaterialSubmit">
						确定
					</v-btn>
					<v-btn color="blue darken-1" text @click="editTabTwoRequestMaterial=null">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>

	</div>
</template>

<script>
	import {
		mapActions
	} from 'vuex'
	import print from 'print-js'
	export default {
		name: 'mes_maintenance_requestorder',
		data: () => ({
			queryChildren: {
				projectCode: '',
				projectName: '',
				equipmentName: '',
				childrenCode: '',
				childrenStatus: null
			},
			notJJMaterialCheckDataList: [],
			currentOrderType: '',
			requestOrtransferOrder: null,
			searchInput: '',
			createProductionPickingDialogVisable: false,
			cuttingDetailHeaderList: [],
			cuttingDetailDataList: [],
			checkCuttingDetailList: [],
			cuttingDetailLoading: true,
			cuttingDetailTotalCount: 0,
			cuttingDetailOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			leftCheckMaterialValid: false,
			//领料单步骤条
			productionPickingEL: 1,
			//领料单 表单信息
			checkMaterialRequestOrderList: [],
			leftMaterialValid: true,
			//领料单 需要数量规则
			leftNeedQtyRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字',
				v => v > 0 || '需求量不能小于0'
			],
			//机加物料信息
			WaitCreateMaterialDataList: [],
			MaterialOtherInfo: {},
			MaterialRequestOrderHeader: [],
			materialDataList: [],
			rightMaterialSearch: '',
			tabOneTotalCount: 0,
			tabOneOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			//子工单信息
			childrenHeaderList: [],
			childrenOrderList: [],
			childrenOrderLoading: true,
			childrenOrderTotalCount: 0,
			childrenOrderOptions: { //页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			checkChildrenList: [],

			//页签二：领料单集合
			requestMaterialOrderList: [],
			tabTwoRequestMaterialOrderHeader: [],
			//总数
			tabTwoLoading: true,
			tabTwoTotalCount: 0,
			tabTwoOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			//搜索的类型
			tabTwoRequestOrderInputType: '',
			//搜索框输入的内容
			tabTwoRequestOrderSearchInput: '',
			//搜索条件
			tabTwoRequestOrderSearchPartemer: {
				materialcode: '',
				materialname: '',
				childrencode: '',
				projectcode: '',
				projectname: '',
				//设备名称
				equipmentName: ''
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			//母工单创建领料单对话框
			createProductionPickingForMasterVisable: false,
			//母工单创建调拨单对话框
			createTransferOrderForMasterVisable: false,
			//编辑领料单对话框
			editTabTwoRequestMaterialDialog: false,
			editTabTwoRequestMaterial: null,
			editTabTwoRequestMaterialValid: true,

			//调拨单对话框
			isOpenTransferOrderDialog: false,
			//调拨单物料头信息
			transferOrderHeader: [],
			//仓库名称
			storageInfoList: [],
			tabThreeTransferOrderHeader: [],
			tabThreeTransferOrderList: [],
			tabThreeLoading: true,
			tabThreeTotalCount: 0,
			tabThreeTransferOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			editTabThreeTransferOrderDialog: false,
			editTabThreeTransferOrder: null,

			//母工单领料单信息
			masterOrderSearchInput: '',
			masterOrderLoading: true,
			masterOrderHeaderList: [],
			masterOrderList: [],
			masterOrderOptions: { //页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			masterOrderTotalCount: 0,

		}),
		watch: {
			masterOrderOptions: {
				handler() {
					this.loadMasterOrderList()
				},
				deep: true
			},
			tabOneOptions: {
				handler() {
					this.loadmaterialDataList(this.requestOrtransferOrder)
				},
				deep: true
			},
			tabTwoOptions: {
				handler() {
					this.loadAllMaterialRequestOrderList()
				},
				deep: true
			},
			childrenOrderOptions: {
				handler() {
					this.loadChildrenList()
				},
				deep: true
			}
		},

		created() {
			//加载物料头信息
			this.loadMaterialRequestOrderHeader()

		},
		methods: {
			...mapActions('mes/getwo_material', [
				//获取物料信息
				'loadmaterialDataListHttp',
				'setIsOpenTransferFunc'
			]),
			//加载物料头信息 TODO
			loadMaterialRequestOrderHeader() {

				this.MaterialRequestOrderHeader = [{
						text: "物料代码",
						value: "materialcode"
					},
					{
						text: "物料名称",
						value: "materialname"
					},
					{
						text: "物料规格",
						value: "materialspecification"
					},
					{
						text: "物料型号",
						value: "materialmodel"
					},
					{
						text: "单位",
						value: "unitname"
					},
					{
						text: "库存数量",
						value: "storgeqty"
					},
					{
						text: "仓库",
						value: "storagename"
					},
				]

				this.transferOrderHeader = [{
						text: '选中项',
						value: 'check'
					},
					{
						text: '调拨数量',
						value: 'needqty'
					},
					{
						text: '目标仓库',
						value: 'storagename'
					},
					{
						text: '备注',
						value: 'description'
					},
					...this.MaterialRequestOrderHeader
				]
				this.transferOrderHeader.pop()
				this.MaterialRequestOrderHeader = [{
						text: '选中项',
						value: 'check'
					},
					{
						text: '需求数量',
						value: 'needqty'
					}, {
						text: '备注',
						value: 'description'
					}, ...this.MaterialRequestOrderHeader
				]
			},
			//加载物料信息
			loadmaterialDataList(type) {
				this.requestOrtransferOrder = type
				var projectdetailIdList = this.checkChildrenList.map(r => r.masterWorkOrder.projectdetailid)
				if (projectdetailIdList.length <= 0) {
					this.$message.error('请选中工单！')
					return
				}
				this.loadmaterialDataListHttp({
					'url':'MES/MESMaterialRequestOrder/GetMaterialDataList',
					'materialCodeOrName': this.rightMaterialSearch,
					'projectdetailIdList': projectdetailIdList,
					'pageNumber': this.tabOneOptions.page,
					'pageSize': this.tabOneOptions.itemsPerPage,
					'type': type
				}).then((response) => {

					if (response.status == 1) {
						this.materialDataList = response.data.data.result
						this.tabOneTotalCount = response.data.data.pagination.totalRecords
						this.materialDataList.forEach(r => {
							r.orgstoragename = r.storagename
						})
						this.WaitCreateMaterialDataList = this.materialDataList
						this.MaterialOtherInfo.now = response.data.now
						this.MaterialOtherInfo.departname = response.data.departname
						this.MaterialOtherInfo.bigRequestCode = response.data.bigRequestCode
						this.MaterialOtherInfo.applyusername = response.data.applyusername
					} else {
						this.$message.error('加载物料信息失败')
					}
				})

			},

			//取消 取消领料单
			cancelAddMaterialRequestOrder() {
				this.checkMaterialRequestOrderList = []
				// this.checkCuttingDetailList = []
				this.productionPickingEL = 1
				this.createProductionPickingForMasterVisable = false
				this.createTransferOrderForMasterVisable = false
				this.leftCheckMaterialValid = false
				this.materialDataList.filter(r => {
					r.check = false
				})

				this.masterOrderList.filter(r => {
					r.check = false
				})

				this.createProductionPickingDialogVisable = false
				this.isOpenTransferOrderDialog = false
				// this.$refs.form.reset()
			},

			copy(obj) {
				return Object.assign({}, obj);
			},
			//选中物料勾选框时触发
			rightMaterialCheckEvent(every) {
				this.leftCheckMaterialValid = false
				this.checkMaterialRequestOrderList = this.materialDataList.filter(r => r.check == true)

				if (!every.check) {
					if (this.materialDataList.filter(r => r.check == true).length <= 0) {
						this.leftCheckMaterialValid = false
					}
				}
				if (this.checkMaterialRequestOrderList.filter(r => parseInt(r.needqty) > 0).length == this
					.checkMaterialRequestOrderList.length && this.checkMaterialRequestOrderList.length > 0) {
					this.leftCheckMaterialValid = true
				}
			},
			//保存需求数量时触发
			saveNeedQty() {
				if (this.checkMaterialRequestOrderList.filter(r => parseInt(r.needqty) > 0).length == this
					.checkMaterialRequestOrderList.length && this.checkMaterialRequestOrderList.length > 0) {
					this.leftCheckMaterialValid = true
				} else {
					this.leftCheckMaterialValid = false
				}
			},

			//加载页签二-领料单
			async loadAllMaterialRequestOrderList() {
				var temp = this.MaterialRequestOrderHeader.filter((val, index, arr) => {
					return index !== 0;
				})
				temp.splice(temp.findIndex(r => r.value == 'description'), 1)
				this.tabTwoRequestMaterialOrderHeader = [{
						'text': '操作',
						'value': 'actions',
						align: 'center'
					},
					{
						'text': '领料单编号',
						'value': 'parentcode',
						align: 'center'
					},
					{
						'text': '领料单流水号',
						'value': 'code',
						align: 'center'
					},
					...temp,
					{
						'text': '子工单号',
						'value': 'childrenOrder.code',
						align: 'center'
					},
					{
						'text': '名称',
						'value': 'childrenOrder.name',
						align: 'center'
					},
					{
						'text': '母工单号',
						'value': 'masterOrder.workcode',
						align: 'center'
					},
					{
						'text': '项目号',
						'value': 'projectcode',
						align: 'center'
					},
					{
						'text': '备注',
						'value': 'description',
						align: 'center'
					}
				]
				Object.keys(this.tabTwoRequestOrderSearchPartemer).forEach(key => {
					this.tabTwoRequestOrderSearchPartemer[key] = ''
				})
				switch (this.tabTwoRequestOrderInputType) {
					case '1':
						this.tabTwoRequestOrderSearchPartemer.materialcode = this.tabTwoRequestOrderSearchInput
						break;
					case '2':
						this.tabTwoRequestOrderSearchPartemer.materialname = this.tabTwoRequestOrderSearchInput
						break;
					case '3':
						this.tabTwoRequestOrderSearchPartemer.childrencode = this.tabTwoRequestOrderSearchInput
						break;
					default:
						break;
				}


				this.tabTwoLoading = true
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/LoadMaterialRequestOrderList?
					materialcode=${this.tabTwoRequestOrderSearchPartemer.materialcode}&
					materialname=${this.tabTwoRequestOrderSearchPartemer.materialname}&
					childrencode=${this.tabTwoRequestOrderSearchPartemer.childrencode}&
					pageNumber=${this.tabTwoOptions.page}&
					pageSize=${this.tabTwoOptions.itemsPerPage}`,
					method: 'get'
				})

				if (response.status == 1) {
					this.requestMaterialOrderList = response.data.result
					this.tabTwoTotalCount = response.data.pagination.totalRecords
					this.tabTwoLoading = false
					// this.tabTwoOptions.page = response.data.pagination.pageNumber
					// this.tabTwoOptions.itemsPerPage = response.data.pagination.pageSize
				} else {
					this.$message.error('加载领料单失败')
				}
			},
			//删除tabTwo 领料单信息
			async deleteTabTwoRequestMaterialOrder(requestid) {
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/Delete/${requestid}`,
					method: 'delete'
				})
				if (response.status == 1) {
					this.$message.success(response.info)
					await this.loadAllMaterialRequestOrderList()
				} else {
					this.$message.error('领料单删除失败！')
				}
			},
			//领料单编辑提交
			async editTabTwoRequestMaterialSubmit() {
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/Update`,
					method: 'put',
					data: this.editTabTwoRequestMaterial
				})

				if (response.status == 1) {
					this.editTabTwoRequestMaterialDialog = false
					this.editTabTwoRequestMaterial = null
					this.$message.success(response.info)
				} else {
					this.$message.error('领料单更新失败！')
				}
			},
				//保存仓库名称
			saveStorageName() {

			},
			//创建调拨单
			async createTransferOrder() {
				var paramterTransferOrderList = []
				if (this.currentOrderType == '机加') {
					this.WaitCreateMaterialDataList.forEach(r => {
						r.parentcode = this.MaterialOtherInfo.bigRequestCode
						r.applydepartmentname = this.MaterialOtherInfo.departname
						r.applyusername = this.MaterialOtherInfo.applyusername
						var cuts = this.checkCuttingDetailList.filter(c => c.id == r.materialid)
						if (cuts != null && cuts.length > 0) {
							r.childrenid = cuts[0].childrenorderid
							r.projectcode = cuts[0].childrenOrder.projectcode
							r.cuttingdetailid = cuts[0].id
						}
						r.materialid = 0
						paramterTransferOrderList.push({
							'originstragename': r.orgstoragename,
							'targetstoragename': r.storagename,
							'cuttingdetailid': r.cuttingdetailid,
							'childrenid': r.childrenid,
							'projectcode': r.projectcode,
							'description': r.description,
							'transferqty': r.needqty,
							'materialid': 0,
							'materialcode': r.materialcode,
							'materialname': r.materialname,
							'parentcode': r.parentcode,
							'applydepartmentname': r.applydepartmentname,
							'applyusername': r.applyusername,
						})
					})
				} else {

					for (var i = 0; i < this.checkChildrenList.length; i++) {
						var children = this.checkChildrenList[i]
						for (var j = 0; j < this.notJJMaterialCheckDataList.length; j++) {
							var material = this.copy(this.notJJMaterialCheckDataList[j])
							material.cuttingdetailid = 0
							material.originstragename = material.orgstoragename
							material.targetstoragename = material.storagename
							material.transferqty = material.needqty
							material.parentcode = this.MaterialOtherInfo.bigRequestCode
							material.applydepartmentname = this.MaterialOtherInfo.departname
							material.applyusername = this.MaterialOtherInfo.applyusername
							material.childrenid = children.id
							material.projectcode = children.projectcode
							paramterTransferOrderList.push(material)
						}
					}
				}

				printJS({
					printable: 'print',
					type: 'html',
					targetStyles: ['*'],
					ignoreElements: ['no-print'],
				})

				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/AddTransferOrder`,
					method: 'post',
					data: paramterTransferOrderList

				})
				if (response.status == 1) {
					this.$message.success(response.info)

					this.cancelAddMaterialRequestOrder()
					this.loadCuttingDetailList()
				} else
					this.$message.error(response.info)
			},
			//为母工单创建调拨单
			async createTransferOrderForMasterSubmit() {
				this.checkMaterialRequestOrderList.forEach(r => {
					r.parentcode = this.MaterialOtherInfo.bigRequestCode
					r.applydepartmentname = this.MaterialOtherInfo.departname
					r.applyusername = this.MaterialOtherInfo.applyusername
					r.childrenid = 0
					r.projectcode = ''
					r.cuttingdetailid = 0
					r.originstragename = r.orgstoragename
					r.targetstoragename = r.storagename
					r.transferqty = r.needqty
				})

				var checkMasterList = this.masterOrderList.filter(r => r.check == true)

				document.getElementById("printMasterWithTransferOrder").style.display = "block"
				printJS({
					printable: 'printMasterWithTransferOrder',
					type: 'html',
					targetStyles: ['*'],
					ignoreElements: ['no-print'],
				})
				document.getElementById("printMasterWithTransferOrder").style.display = "none"
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/AddTransferOrderForMaster`,
					method: 'post',
					data: {
						requestMaterialList: this.checkMaterialRequestOrderList,
						masterList: checkMasterList
					}
				})

				if (response.status == 1) {
					this.createTransferOrderForMasterVisable = false
					this.loadAllMaterialRequestOrderList()
					this.$message.success(response.info)
				} else {
					this.$message.error(response.info)
				}

			},
			//提交：为主工单创建领料单
			async createMasterOrderRequestOrderSubmit() {

				this.checkMaterialRequestOrderList.forEach(r => {
					r.parentcode = this.MaterialOtherInfo.bigRequestCode
					r.applydepartmentname = this.MaterialOtherInfo.departname
					r.applyusername = this.MaterialOtherInfo.applyusername
					r.childrenid = 0
					r.projectcode = ''
					r.cuttingdetailid = 0
				})

				var checkMasterOrderList = this.masterOrderList.filter(r => r
					.check == true)

				document.getElementById("printMasterWithRequestOrder").style.display = "block"
				printJS({
					printable: 'printMasterWithRequestOrder',
					type: 'html',
					targetStyles: ['*'],
					ignoreElements: ['no-print'],
				})
				document.getElementById("printMasterWithRequestOrder").style.display = "none"
				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/AddRequestOrderForMaster`,
					method: 'post',
					data: {
						requestMaterialList: this.checkMaterialRequestOrderList,
						masterList: checkMasterOrderList
					}
				})

				if (response.status == 1) {
					this.createProductionPickingForMasterVisable = false
					this.loadAllMaterialRequestOrderList()
					this.$message.success(response.info)
				} else {
					this.$message.error(response.info)
				}

			},
			//加载 母工单信息
			async loadMasterOrderList() {

				const response = await this.$httpRequest({
					url: `MES/MESMaterialRequestOrder/LoadMasterList?
					pCodePNameMNameMCode=${this.masterOrderSearchInput}&
					pageNumber=${this.masterOrderOptions.page}&
					pageSize=${this.masterOrderOptions.itemsPerPage}`,
					method: 'get'
				})

				if (response.status == 1) {
					this.masterOrderHeaderList = response.data.headers
					this.masterOrderHeaderList = [{
							'text': '选项',
							'value': 'check',
							'align': 'center'
						},
						...this.masterOrderHeaderList
					]
					this.masterOrderList = response.data.data.result
					this.masterOrderTotalCount = response.data.data
						.pagination.totalRecords
					this.masterOrderLoading = false
				} else {
					this.$message.error('加载母工单失败！')
				}
			},
			// 非机加领料单对话框选中事件
			checkMultipleMaterialEvent(items) {
				this.notJJMaterialCheckDataList = items

			},
		}
	}
</script>

<style scoped>
	@import url("../../../../../../public/css/print.css");
</style>
